<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<style>
body{height:auto;font-family: "Microsoft YaHei";}
button{font-family: "SimSun","Helvetica Neue",Helvetica,Arial;}
</style>
<body class="hold-transition box box-main">
	<input id="lookupId"   name="lookupId"    type="hidden" th:value="${project.apiProjectnameId}"/>
	<input id="lookupName" name="lookupName"  type="hidden" th:value="${project.description}"/>
	<div class="wrapper"><div class="treeShowHideButton" onclick="$.tree.toggleSearch();">
		<label id="btnShow" title="显示搜索" style="display:none;">︾</label>
		<label id="btnHide" title="隐藏搜索">︽</label>
	</div>
	<div class="treeSearchInput" id="search">
		<label for="keyword">关键字：</label><input type="text" class="empty" id="keyword" maxlength="50">
		<button class="btn" id="btn" onclick="$.tree.searchNode()"> 搜索 </button>
	</div>
	<div class="treeExpandCollapse">
		<a href="#" onclick="$.tree.expand()">展开</a> /
		<a href="#" onclick="$.tree.collapse()">折叠</a>
	</div>
	<div id="tree" class="ztree treeselect"></div>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script th:inline="javascript">
		$(function() {
			var url = ctx + "module/project/treeData";
			var options = {
			    id:'tree',
		        url: url,
		        expandLevel: 0,
		        onClick : zOnClick,
                // check: {
                //     enable: true,
                //     nocheckInherit: false
                // }
		    };
			$.tree.init(options);
		});
		
		function zOnClick(event, lookupId, treeNode) {
		    var lookupId = treeNode.id;
		    var lookupName = treeNode.name;
		    $("#lookupId").val(lookupId);
		    $("#lookupName").val(lookupName);
		    // console.log(treeNode);
		}


	</script>


	<script th:inline="javascript">
        /*<![CDATA[*/
        var id = [[${project.apiProjectnameId}]];
        /*]]>*/
        // console.log("id="+id);
        var zTree_Menu = $.fn.zTree.getZTreeObj("tree");

        function positioningNode(){
            // console.log(zTree_Menu);
            setTimeout(function () {
                zTree_Menu = $.fn.zTree.getZTreeObj("tree");
                // console.log(zTree_Menu);
                if(zTree_Menu!=undefined){
                    var nodeList = $._tree.getNodesByParam("id",id );
                    for (var i=0, l=nodeList.length; i<l; i++) {
                        var node=nodeList[i];
                        zTree_Menu.expandNode(node, true, false, false);
                        zTree_Menu.selectNode(node,true);//指定选中ID的节点

                    }

                }else {
                    positioningNode();
				}
            }, 1000);
		}

        positioningNode();


	</script>
</body>
</html>
